package com.jjb.saas.demo.infrastructure.gateway;

import com.jjb.saas.demo.domain.role.gateway.RoleGateway;
import com.jjb.saas.demo.domain.role.model.RoleE;
import com.jjb.saas.demo.infrastructure.converter.RoleConvertor;
import com.jjb.saas.demo.infrastructure.persistence.domainobject.RoleDO;
import com.jjb.saas.demo.infrastructure.persistence.repository.RoleRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;


/**
 * @author tzh * @date 2022年07月08日 18:48
 */
@Service
@AllArgsConstructor
public class RoleGatewayImpl implements RoleGateway {
    private final RoleRepository roleRepository;
    private final RoleConvertor roleConvertor;

    @Override
    public Boolean add(RoleE roleE) {
        RoleDO roleDO = roleConvertor.convertEToDO(roleE);
        roleRepository.save(roleDO);
        return Boolean.TRUE;
    }

    @Override
    public Boolean update(RoleE roleE) {
        RoleDO roleDO = roleConvertor.convertEToDO(roleE);
        roleRepository.updateById(roleDO);
        return Boolean.TRUE;
    }

    @Override
    public Boolean updateSelf(RoleE roleE) {
        RoleDO roleDO = roleConvertor.convertEToDO(roleE);
        return roleRepository.updateById(roleDO);
    }

}
